package models.mappers;

import java.util.Date;
import java.util.List;
import java.util.Map;

import models.BackCount;
import models.User;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;
import org.apache.ibatis.annotations.Update;

import vos.BackCountSearchVo;
import vos.BackCountSubSearchVo;
import vos.BackCountVo;
import vos.BackInfoVo;
import vos.CountHistorySearchVo;
import vos.UserInfoSearchVo;

public interface BackCountMapper {
	/**
	 * 获取上次统计时间
	 * @param enddate 
	 * @param startdate 
	 *
	 * @Title: getLastTime 
	 * @param startdateStr
	 * @param enddateStr
	 * @return
	 * @return: Date
	 */
	@Select("select max(enddate) from backcount where cmonth=#{cmonth}")
	Date getLastTime(String cmonth);
	/**
	 * 统计本月返款统计
	 *
	 * @Title: countMonth 
	 * @param startdate
	 * @param enddate
	 * @return: void
	 */
	void countMonth(Map<String,Object> map);
	/**
	 * 获取未保存列表
	 *
	 * @Title: getCount 
	 * @param map
	 * @return
	 * @return: List<BackCountVo>
	 */
	List<BackCountVo> getCount(BackCountSearchVo vo);
	/**
	 * 获取列表总数
	 *
	 * @Title: count 
	 * @param vo
	 * @return
	 * @return: long
	 */
	long count(BackCountSearchVo vo);
	/**
	 * 根据月份统计
	 * @param datestr 
	 *
	 * @Title: countByMonth 
	 * @return
	 * @return: Long
	 */
	@Select("select count(1) from backcount where cmonth=#{datestr}")
	Long countByMonth(String datestr);
	/**
	 * 统计未保存的记录数
	 *
	 * @Title: countBySave 
	 * @return
	 * @return: Long
	 */
	@Select("select count(1) from backcount where issave=false")
	Long countBySave();
	/**
	 * 重新统计
	 *
	 * @Title: reCount 
	 * @return
	 * @return: boolean
	 */
	boolean reCount(Map<String,Object> map);
	/**
	 * 获取未保存记录
	 *
	 * @Title: getNotSave 
	 * @return
	 * @return: List<BackCount>
	 */
	@Select("select shopid,cmonth,startdate,enddate from backcount where issave=false")
	List<BackCount> getNotSave();
	/**
	 * 删除未保存的记录
	 *
	 * @Title: delCount 
	 * @return: void
	 */
	@Delete("delete from backcount where issave=false")
	void delCount();
	/**
	 * 保存未保存记录
	 *
	 * @Title: saveCount 
	 * @return: void
	 */
	void saveCount();
	/**
	 * 更新记录为保存
	 *
	 * @Title: updateSave 
	 * @return: void
	 */
	@Update("update backcount set issave=true where issave=false")
	void updateSave();
	/**
	 * 根据门店和月份查询数据
	 *
	 * @Title: getByDealerMonth 
	 * @param shopid
	 * @param cmonth
	 * @return
	 * @return: BackCount
	 */
	@Select("select * from backcount where shopid=#{shopid} and cmonth=#{cmonth}")
	BackCount getByShopMonth(@Param("shopid")String shopid, @Param("cmonth")String cmonth);
	/**
	 * 更新最新统计价格
	 *
	 * @Title: updatePrice 
	 * @param map
	 * @return: void
	 */
	void updatePrice(Map<String, Object> map);
	/**
	 * 统计子表
	 *
	 * @Title: countSub 
	 * @param vo
	 * @return
	 * @return: long
	 */
	long countSub(BackCountSubSearchVo vo);
	/**
	 * 获取子表列表
	 *
	 * @Title: getCountSub 
	 * @param vo
	 * @return
	 * @return: List<BackCountVo>
	 */
	List<BackCountVo> getCountSub(BackCountSubSearchVo vo);
	/**
	 * 根据门店id和月份获取开始结束时间
	 *
	 * @Title: getStartEndDate 
	 * @param shopid 门店id
	 * @param string 月份
	 * @return
	 * @return: Map<String,String>
	 */
	@Select("select startdate,enddate from backcount where shopid=#{shopid} and cmonth=#{cmonth}")
	Map<String, Date> getStartEndDate(@Param("shopid")String shopid, @Param("cmonth")String fmonth);
	/**
	 * 统计历史统计信息
	 *
	 * @Title: countCountHistory 
	 * @param vo
	 * @return
	 * @return: long
	 */
	long countCountHistory(CountHistorySearchVo vo);
	/**
	 * 获取历史统计信息列表
	 *
	 * @Title: listCountHistory 
	 * @param vo
	 * @return
	 * @return: List<BackInfoVo>
	 */
	List<BackCountVo> listCountHistory(CountHistorySearchVo vo);
	/**
	 * 获取历史子表信息
	 *
	 * @Title: listSubHistory 
	 * @param vo
	 * @return
	 * @return: List<BackCountVo>
	 */
	List<BackCountVo> listSubHistory(CountHistorySearchVo vo);
	/**
	 * 统计历史子表
	 *
	 * @Title: countSubHistory 
	 * @param vo
	 * @return
	 * @return: long
	 */
	long countSubHistory(CountHistorySearchVo vo);
	/**
	 * 获取引用统计返款总数
	 *
	 * @Title: countByBack 
	 * @param vo
	 * @return
	 * @return: long
	 */
	long countByBack(BackCountSearchVo vo);
	/**
	 * 获取引用统计返款记录
	 *
	 * @Title: getCountByBack 
	 * @param vo
	 * @return
	 * @return: List<BackCountVo>
	 */
	List<BackCountVo> getCountByBack(BackCountSearchVo vo);
	/**
	 * 根据id集合获取记录
	 *
	 * @Title: getByIds 
	 * @param map
	 * @return
	 * @return: List<BackInfoVo>
	 */
	List<BackCountVo> getByIds(Map<String, Object> map);
	/**
	 * 批量驳回
	 *
	 * @Title: betchReject 
	 * @param map
	 * @return: void
	 */
	void betchReject(Map<String, Object> map);
	/**
	 * 根据id查询记录
	 *
	 * @Title: getById 
	 * @param id
	 * @return
	 * @return: BackCountVo
	 */
	@Select("select * from backcount_view where id=#{id}")
	BackCountVo getById(Long id);
	/**
	 * 驳回
	 *
	 * @Title: reject 
	 * @param map
	 * @return: void
	 */
	@Update("update backcount set isreject=true,modifytime=#{modifytime},"
			+ "modifyname=#{modifyname},rejreason=#{rejreason} where id=#{id}")
	void reject(Map<String, Object> map);
	
}
